#coding: utf-8
# Create your views here.
from main.models import Post,Categoria
from django.shortcuts import render_to_response

def index(request):
    desc = request.GET.get('categoria',"")
    if desc == "":
        return render_to_response('index.html',{'ultimos_posts': Post.objects.order_by('-data'), 
                                                'categorias': Categoria.objects.all()} )
    else:            
        c = Categoria.objects.filter(descricao=desc)
        return render_to_response('index.html',{'ultimos_posts': Post.objects.filter(categoria=c).order_by('-data'), 
                                                'categorias': Categoria.objects.all()} )